package com.mrlv.email;

import com.mrlv.email.entity.EmailMessage;
import com.mrlv.email.utils.EmailUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.File;

/**
 * @author lvshiyu
 * @description: TODO
 * @date 2022年04月11日 9:44
 */
@SpringBootApplication
@Controller
public class BootApplication {

    @Resource
    private EmailUtil emailUtil;

    @RequestMapping("/test")
    @ResponseBody
    public String test() {
        EmailMessage emailMessage = new EmailMessage();
        String content = "<html>\n" +
                "<body>\n" +
                "    <h1>这是Html格式邮件!,不信你看邮件，我字体比一般字体还要大</h1>\n" +
                "   <img width='250px' src='cid:" + "123" + "'>" +
                "</body>\n" +
                "</html>";
        emailMessage.setContent(content);
        emailMessage.setSubject("这是一条测试邮件");
        emailMessage.setTos(new String[]{"826303461@qq.com"});
        emailMessage.addAttachment("438.jpg", new File("D:\\temp\\438.jpg"));
        emailMessage.addAttachment("4381.jpg", new File("D:\\temp\\438.jpg"));
        emailMessage.addInlineFile("123", new File("D:\\temp\\438.jpg"));
        emailUtil.sendMimeMessage(emailMessage);
        return "";
    }

    public static void main(String[] args) {
        SpringApplication.run(BootApplication.class, args);
    }
}
